package nc.oa.login;


	import java.util.HashMap;
	import java.util.Map;

	import org.springframework.http.HttpEntity;
	import org.springframework.http.HttpHeaders;
	import org.springframework.http.HttpMethod;
	import org.springframework.http.ResponseEntity;
	import org.springframework.web.client.RestTemplate;

	import com.alibaba.druid.util.StringUtils;
	import com.alibaba.fastjson.JSON;

	import nc.vo.pub.BusinessException;
	import nccloud.api.rest.log.OPMLogger;


	public class CommonSendMethod {
		//这些都是列子	start
	  static Map<String,Object> maps=new HashMap<String,Object>();
	  static {
		  maps.put("sendTO","http://127.0.0.1:8080/api/sys-notify/sysNotifyTodoRestService/getTodo");
	  }
	  //end
		public static String  sendMessage(Map<String,Object> params,String method,String url) throws BusinessException {
			
			// 定义header对象
		    HttpHeaders headers = new HttpHeaders();
		    //判空
	        if(StringUtils.isEmpty(url)) {
	        	 url=(String) maps.get(method);
	        }
	        // 定义http请求实体对象
		    HttpEntity<Map<String,Object>> entity = new HttpEntity<Map<String,Object>>(params,headers);
		    
		    // 发送请求
		    RestTemplate template = new RestTemplate();
		    ResponseEntity<Map> exchange =null;
		    try {
		      exchange = template.exchange(url, HttpMethod.POST, entity, Map.class);
		    }catch(Exception e) {
		    	OPMLogger.error("##::推送OA异常:请检查传入参数和传入路径:" + e.getMessage());
		    	throw new BusinessException("消息推送OA异常:" + e.getMessage());
		    }
		   if(exchange.getStatusCodeValue()!=200) {
			   OPMLogger.error("##::推送OA异常，返回状态异常:"+exchange.getStatusCodeValue());
				throw new BusinessException("推送OA异常，返回状态异常:"+exchange.getStatusCodeValue());
		   }
		    
		    if(!exchange.getBody().get("returnState").equals(2)) {
		    	OPMLogger.error("##::推送OA异常:"+exchange.getBody().get("message"));
		    }

		     String jsonString=JSON.toJSONString(exchange.getBody());
		    
		    
			return  jsonString;
		  }

		}
		